home *** CD-ROM | disk | FTP | other *** search
- /*
- ** fossil.c -- preliminary C versions of fossil interface functions
- */
-
- #include <dos.h>
- #include "fossil.h"
-
- unsigned char fossilMaxFunc = 0;
- unsigned char fossilRevision = 0;
-
-
- /*
- ** port_open, port_close -- open and close a port for access
- **
- ** returns non-zero on error
- **
- ** As with all these functions, the "port" argument indexes the fossil's
- ** port sequence, which need not be the same as the DOS order, that is,
- ** port 0 need not be COM1.
- **
- ** Side Effects:
- **
- ** port_open asserts DTR if the open succeeds
- ** the globals fossilMaxFunc and fossilRevision are initialized
- **
- ** port_close does NOT affect DTR
- **
- ** Oddities:
- **
- ** If port == 0xff, the fossil may perform setup/wrapup to make the keyboard
- ** and display functions usable. The fossil calls that access these devices
- ** are not currently supported in this interface library.
- */
-
- int pascal port_open(int port)
- {
- union REGS r;
-
- r.h.ah = 4;
- r.x.dx = port;
- r.x.bx = 0; /* must not be 0x4f50! */
- int86(0x14, &r, &r);
- if (r.x.ax == 0x1954)
- {
- fossilMaxFunc = r.h.bl;
- fossilRevision = r.h.bh;
- return 0;
- }
- return -1;
- }
-
- int pascal port_close(int port)
- {
- union REGS r;
-
- r.h.ah = 5;
- r.x.dx = port;
- int86(0x14, &r, &r);
- return 0;
- }
-
- /*
- ** port_setBaud -- set serial port's speed and other parameters
- */
-
- void pascal port_setBaud(int port, int baud)
- {
- union REGS r;
-
- r.h.ah = 0;
- r.h.al = baud;
- r.x.dx = port;
- int86(0x14, &r, &r);
- }
-
- /*
- ** port_flow -- set flow-control mode
- **
- ** returns (nothing?)
- **
- ** "mode" should be one of the symbols defined in the header
- */
-
- void pascal port_flow(int port, int mode)
- {
- union REGS r;
-
- r.h.ah = 15;
- r.x.dx = port;
- r.h.al = mode;
- int86(0x14, &r, &r);
- }
-
- /*
- ** port_dtr -- control DTR line
- **
- ** Asserts (enable != 0) or deserts (enable == 0) the port's DTR line
- */
-
- void pascal port_dtr(int port, int enable)
- {
- union REGS r;
-
- r.h.ah = 6;
- r.h.al = enable ? 1 : 0;
- r.x.dx = port;
- int86(0x14, &r, &r);
- }
-
- /*
- ** port_status -- get port's status
- **
- ** returns a bit-mapped status (see PS_... symbols in header)
- */
-
- int pascal port_status(int port)
- {
- union REGS r;
-
- r.h.ah = 3;
- r.x.dx = port;
- int86(0x14, &r, &r);
- return r.x.ax;
- }
-
- /*
- ** port_read, port_write -- non-blocking multi-character data transfer
- **
- ** returns the number of characters actually transferred
- */
-
- int pascal port_read(int port, char *buf, int n)
- {
- union REGS r;
- struct SREGS s;
-
- r.h.ah = 24;
- r.x.dx = port;
- r.x.di = (int)buf; /* near model assumed here */
- r.x.cx = n;
- segread(&s);
- s.es = s.ds; /* and here */
- int86x(0x14, &r, &r, &s);
- return r.x.ax;
- }
-
- int pascal port_write(int port, const char *buf, int n)
- {
- union REGS r;
- struct SREGS s;
-
- r.h.ah = 25;
- r.x.dx = port;
- r.x.di = (int)buf; /* near model assumed here */
- r.x.cx = n;
- segread(&s);
- s.es = s.ds; /* and here */
- int86x(0x14, &r, &r, &s);
- return r.x.ax;
- }
-